//
//  KLBaseModel.m
//  KLBookStore
//
//  Created by apple on 2017/10/15.
//  Copyright © 2017年 NetEaseExam. All rights reserved.
//

#import "KLBaseModel.h"

@implementation KLBaseModel

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    NSString *msg = [NSString stringWithFormat:@"%s is not implemented "
                     "for the class %@", sel_getName(_cmd),self];
    @throw [NSException exceptionWithName:@"BookModelInitializerException" reason:msg userInfo:nil];
}

- (instancetype)initWithFMResultSet:(FMResultSet *)resultSet {
    NSString *msg = [NSString stringWithFormat:@"%s is not implemented "
                     "for the class %@", sel_getName(_cmd),self];
    @throw [NSException exceptionWithName:@"BookModelInitializerException" reason:msg userInfo:nil];
}

- (id)copyWithZone:(NSZone *)zone {
    NSString *msg = [NSString stringWithFormat:@"%s is not implemented "
                     "for the class %@", sel_getName(_cmd),self];
    @throw [NSException exceptionWithName:@"BookModelInitializerException" reason:msg userInfo:nil];
}

#pragma mark - convert

- (NSArray *)modelArrayFromDictionaryArray:(NSArray *)array withModelClass: (Class)modelClass{
    
    NSParameterAssert(modelClass != nil);
    NSParameterAssert([modelClass isSubclassOfClass:[KLBaseModel class]]);
    
    NSMutableArray *models = [@[] mutableCopy];
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        KLBaseModel *model = [[modelClass alloc] initWithDictionary:obj];
        [models addObject:model];
    }];
    return models;
}

@end
